<?php
namespace jy_qiuyuyue;
defined('BY_JYA') or exit('error');
/*
	任务
*/
class task extends \plugin{
	/*
		订单状态UP
	*/
	public function orderup($ismanage=false){
		$basic=$this->plugin_setting('basic');
		$params=array('uniacid'=>$_SESSION['uniacid']);
		$pindex = max(1, 0);
		$psize = 10;
		$total='';
		if(!$ismanage){
			$params['mid']=$_SESSION['uid'];
		}
		//关闭订单
		$params['status']=0;
		$basic['orderpay_outtime']=intval($basic['orderpay_outtime'])?:24;
		$orderpay_outtime=TIMESTAMP-intval($basic['orderpay_outtime'])*3600;
		$params['createtime <']=$orderpay_outtime;
		$order = pdo_getslice('jy_qiuyuyue_order',$params,array($pindex,$psize),$total,array('id'));
		if($order){
			foreach($order as $a){
				if($a['id']){
					$this->model('order')->order_cancel($a['id'],true);
				}			
			}
		}
		//确认收货
		$params['status']=2;
		$basic['ordercheck_outtime']=intval($basic['ordercheck_outtime'])?:7;
		$ordercheck_outtime=TIMESTAMP-intval($basic['ordercheck_outtime'])*24*3600;
		$params['createtime <']=$ordercheck_outtime;
		$order = pdo_getslice('jy_qiuyuyue_order',$params,array($pindex,$psize),$total,array('id'));
		if($order){
			foreach($order as $a){
				$this->model('order')->order_receive($a['id']);
			}
		}
		//已支付，未发货订单，超时完成
		if(intval($basic['orderfinish_outtime'])>0){
			$params['status']=1;
			$orderfinish_outtime=TIMESTAMP-intval($basic['orderfinish_outtime'])*3600;
			$params['createtime <']=$orderfinish_outtime;
			$order = pdo_getslice('jy_qiuyuyue_order',$params,array($pindex,$psize),$total,array('id'));
			if($order){
				foreach($order as $a){
					$this->model('order')->order_receive($a['id']);
				}
			}
		}
	}
}